package logic.moves;

import java.io.Serializable;

import logic.Country;

public class ExchangeMove implements GameMove, Serializable  {
	
	private static final long serialVersionUID = 1L;
	public static final String move_type = "EXCHANGEMOVE";
	private boolean moved;
	
	private Country from;
	private Country to;
	private int amount;
	
	public ExchangeMove(Country from, Country to, int amount) {
		this.moved = false;
		this.from = from;
		this.to = to;
		this.amount = amount;
	}

	/**
	 * @return move type as string
	 */
	public String getType() {
		return move_type;
	}

	/**
	 * @return true if move has been made
	 */
	public boolean hasMoved() {
		return this.moved;
	}

	/**
	 * @Moves soldiers between countries
	 */

	public boolean makeMove(){	
		if(amount > from.getSoldiers()-1) return false;
		if(hasMoved()) return false;
		from.reduceSoldiers(amount);
		to.addSoldiers(amount);
		return true;

	}

	public void printDoMove() {
		System.out.println(amount + " soldiers has moved from " + this.from.toString() + " to " + this.to.toString());
	}

	public void printUndoMove() {
		System.out.println(amount + " soldiers has moved back from " + this.to.toString() + " to " + this.from.toString());
	}

	public void restore() {
		if (hasMoved()) {
			from.addSoldiers(amount);
			to.reduceSoldiers(amount);
		}
	}

	
	public void printShortDescription() {
		// TODO Auto-generated method stub
		
	}

	public String getBriefDo() {
		return amount + " soldiers has moved from " + this.from.toString() + " to " + this.to.toString();
	}

	public String getBriefUndo() {
		return amount + " soldiers has moved back from " + this.to.toString() + " to " + this.from.toString();
	}
}
